﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace HHL_Acc.HHL_Util
{
    public class CommonGuiUtil
    {
        /// <summary>
        /// Tao column header cho gridview
        /// </summary>
        /// <param name="gv">GridView 's name</param>
        /// <param name="columnItems">list column</param>
        public static void CreateColumns(ref DataGridView gv, List<ColumnItem> columnItems)
        {
            DataGridViewColumn col = null;
            ColumnItem columnItem = null;
            if (columnItems != null)
            {
                for (int i = 0; i < columnItems.Count; i++)
                {
                    columnItem = columnItems[i];
                    col = new DataGridViewColumn();
                    col.HeaderText = columnItem.Text;
                    col.Name = columnItem.Name;
                    col.DataPropertyName = columnItem.Name;
                    col.Width = columnItem.Width;
                    col.DefaultCellStyle = new DataGridViewCellStyle();
                    col.CellTemplate = new DataGridViewTextBoxCell();
                    gv.Columns.Add(col);
                    gv.ColumnHeadersVisible = true;
                    gv.AutoGenerateColumns = false;
                }
            }
        }
    }
}